//package edu.ncsu.csc.camera;

// for SPOT
//import com.sun.squawk.util.StringTokenizer;
// for PC
import java.util.StringTokenizer;

public class TPacket
{
	public int mx;
	public int my;
	public int x1;
	public int y1;
	public int x2;
	public int y2;
	public int pixels;
	public int confidence;
	
	public TPacket()
	{

	}
	
	public static TPacket build(String str)
	{
		StringTokenizer st = new StringTokenizer(str, " \r");
		int tokens = st.countTokens();
		if(tokens == 9)	// S rmean gmean bmean rdev gdev bdev
		{
			if(st.nextToken().equals("T"))
			{
				TPacket packet = new TPacket();
				packet.mx = Integer.parseInt(st.nextToken());
				packet.my = Integer.parseInt(st.nextToken());
				packet.x1 = Integer.parseInt(st.nextToken());
				packet.y1 = Integer.parseInt(st.nextToken());
				packet.x2 = Integer.parseInt(st.nextToken());
				packet.y2 = Integer.parseInt(st.nextToken());
				packet.pixels = Integer.parseInt(st.nextToken());
				packet.confidence = Integer.parseInt(st.nextToken());
				return packet;
			}
		}
		return null;
	}

	public String toString()
	{
		String result = "T ";
		result += (0xFF & (int)mx) + " ";
		result += (0xFF & (int)my) + " ";
		result += (0xFF & (int)x1) + " ";
		result += (0xFF & (int)y1) + " ";
		result += (0xFF & (int)x2) + " ";
		result += (0xFF & (int)y2) + " ";
		result += (0xFF & (int)pixels) + " ";
		result += (0xFF & (int)confidence) + " ";
		
		return result;
	}
	
}